﻿/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.owl;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.Ontology;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.ontspace.QueryManager;
import org.ontspace.Session;

/**
 * General Implementation of Query Managers
 * to Manages repositories queries
 */
public class QueryManagerImpl implements QueryManager {

    private static MetadataRepositoryImpl _rep;
    private static List<Ontology> _onts =
            new ArrayList<Ontology>();
    private static List<URI> _uriList =
            new ArrayList<URI>();
    private static String _nsName =
            "http://www.cc.uah.es/ie/ont/lom2owl";

    public QueryManagerImpl(MetadataRepositoryImpl rep)
            throws ClassNotFoundException, NoSuchMethodException {

    }

    /**
     * Add the ontology asociated with the specified query manager
     * @param ont The ontology to add
     */
    public void addOntologyRef(Ontology ont) {
        _onts.add(ont);
    }

    /**
     * Gets a list with the URIs of the ontologies required by the query manager
     * @return A list whith the USIs of the required ontologies
     */
    public List<URI> getRequiredOntologies() {
        return _uriList;
    }

    /**
     * Gets the session to which the Query Manager is associated,
     * assigning a anonymous userId
     * @return  The sesion with anonymous user identifier
     */
    public Session getAnonymousSession() {
        return new SessionImpl(_rep);
    }

    /**
     * Gets the session to which the Query Manager is associated for the
     *  given userId
     * @param userId The user identifier to asociate
     * @return The Session to which the Query Manager is associated for the
     *  given userId
     */
    public Session getSessionId(String userId) {
        return new SessionImpl(_rep, userId);
    }

    /**
     * Gets the ontology model
     * @return the ontology model associated at query manager
     */
    public OntModel getOntologyModel() {
        OntModel ontmodel =
                null;

        for (int i =
                0; i < _onts.size(); i++) {
            Ontology ont =
                    _onts.get(i);

            System.out.println(ont.getNameSpace() + ont.getLocalName());
            String ns =
                    ont.getNameSpace() + ont.getLocalName();
            if (ns.compareTo(_nsName) == 0) {
                ontmodel =
                        ont.getOntModel();

            }
        }
        return ontmodel;
    }
}
